#include <util/Rank.h>
#include <gtest/gtest.h>
#include <cmath>

using namespace util;

TEST(TestRank, test1)
{
  // Rank(std::size_t numElements, std::size_t rank)
  Rank r(1, 1);

  ASSERT_TRUE(r.result(0));
}

TEST(TestRank, test2)
{
  Rank r(2, 1);
  
  r.addElement(0, 1.0);
  r.addElement(1, 2.0);

  ASSERT_TRUE(r.result(0));
  ASSERT_FALSE(r.result(1));
}

TEST(TestRank, test3)
{
  Rank r(3, 1);

  r.addElement(0, 3.0);
  r.addElement(1, 1.0);
  r.addElement(2, 2.0);

  ASSERT_TRUE(r.result(1));
  ASSERT_FALSE(r.result(0));
  ASSERT_FALSE(r.result(2));
}

TEST(TestRank, test4)
{
  Rank r(3, 2);

  r.addElement(0, 3.0);
  r.addElement(1, 1.0);
  r.addElement(2, 2.0);

  ASSERT_TRUE(r.result(1));
  ASSERT_TRUE(r.result(2));
  ASSERT_FALSE(r.result(0));
}

TEST(TestRank, test5)
{
  Rank r(6, 2);

  r.addElement(0, 3.0);
  r.addElement(1, 1.0);
  r.addElement(2, 2.0);
  r.addElement(3, 3.0);
  r.addElement(4, 1.0);
  r.addElement(5, 2.0);

  ASSERT_TRUE(r.result(1));
  ASSERT_TRUE(r.result(4));
  ASSERT_FALSE(r.result(0));
  ASSERT_FALSE(r.result(2));
  ASSERT_FALSE(r.result(3));
  ASSERT_FALSE(r.result(5));
}

TEST(TestRank, test6)
{
  Rank r(6, 4);

  r.addElement(0, 3.0);
  r.addElement(1, 1.0);
  r.addElement(2, 2.0);
  r.addElement(3, 3.0);
  r.addElement(4, 1.0);
  r.addElement(5, 2.0);

  ASSERT_TRUE(r.result(1));
  ASSERT_TRUE(r.result(4));
  ASSERT_TRUE(r.result(5));
  ASSERT_TRUE(r.result(2));
  ASSERT_FALSE(r.result(0));
  ASSERT_FALSE(r.result(3));
}
